<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%
	request.setAttribute("path", request.getContextPath());
%>
<script type="text/javascript">
function validateGroupInfo(){
	
	$("#id").change(function (){
		if(check.codeId("id")){
			$.post("${root}/app/group/exist/"+$("#id").val(),function(result){
				 if(result){
					 	common.showClientErrorTip("id",'<spring:message code="err0004"/>');
					 }else{
						 common.destoryTip("id");
					}
			});
		}
	});
	$("#name").change(function (){
		check.emptyCheck("name");
	});
	
}
function validateExt(){
	
	var gLen = $("input[name='resources']:checked").size();
	if(gLen < 1){
		//common.modalGlobalMessage("请选择用户组权限!");
		//return false;
	}
	return  true;
}
$(function () {
	validateGroupInfo();
});

function saveGroup(){
	
		var isModify = $("#modifyFlag").val();
		var uri = "${root}/app/group/add"
		if(isModify == "true"){
			uri = "${root}/app/group/modify"
			if(check.emptyCheck("name")){
				if(validateExt()){
					common.ajaxSubmit(uri,"groupForm","修改用户组失败","",'common.reload("${root}/view/page?loc=group_list&h=h01&n=n05")');
				}
			}
		}
		if(isModify == "false"){
			if(check.codeId("id") & check.emptyCheck("name")){
				if(validateExt()){
					common.ajaxSubmit(uri,"groupForm","保存新用户组失败","",'common.reload("${root}/view/page?loc=group_list&h=h01&n=n05")');
				}
			}
		}
		
	}
</script>
<form class="form-horizontal" id="groupForm" role="form">
	<jsp:include page="../../base/token.jsp" />
	<div class="control-group">
	 	 <label class="control-label">用户组:</label>
	 	<div class="controls">
	 		<c:choose>
				<c:when test="${group == null }">
					<input type="hidden"  id="modifyFlag" value="false" />
					<input class="input-xlarge"  id="id"  name="id"  maxlength="10" type="text" />
				</c:when>
				<c:otherwise>
					<input type="hidden"  id="modifyFlag" value="true" />
					<input type="hidden" id="id"  name="id" value="${group.id }" />
					<c:out value="${group.id }"/>
				</c:otherwise>
			</c:choose>
	 	</div>
	</div>
	<div class="control-group">
	 	 <label class="control-label">用户组名称:</label>
	 	<div class="controls">
	 		<input type="hidden" />
	 		<input class="input-xlarge" id="name" name="name" value="${group.name}" maxlength="25"  type="text" />
	 	</div>
	</div>
	<div class="control-group">
		 <label class="control-label">用户组权限:</label>
	 	 <div class="controls">
	 	 		<jsp:include page="../common/resource_list.jsp"></jsp:include>
	 	 </div>
	</div>
	<div class="form-actions text-center">
      <button type="button" class="btn btn-success" onclick="saveGroup()">保存</button>
    </div>
</form>

